package com.winchain.chainbill.receivables.biz.impt.cmd;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.bee.base.utils.SpringContextUtil;
import com.shell.bee.base.utils.SystemUtil;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICommand;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.SysDateUtil;
import com.winchain.chainbill.receivables.base.po.ArOperation;
import com.winchain.chainbill.receivables.base.po.ArRecord;
import java.math.BigDecimal;
import org.springframework.stereotype.Component;

@Component
public class ReceivablesQuotaCmd implements ICommand<ArRecord> {
	public boolean execute(CommandContext<ArRecord> context) throws Exception {
		boolean timeout = ((Boolean) context.getValue("Timeout")).booleanValue();
		if (!timeout) {
		}
		return false;
	}

	protected AcctTxRec getTxRec(CommandContext<ArRecord> context) {
		ArRecord record = (ArRecord) context.getSource();
		String bizType = ((ArOperation) context.getValue("Operation")).getBizType();
		String optType = "qt_snd";
		BigDecimal amount = record.getCreditMoney();
		BigDecimal cmo = record.getCreditMoneyOrig();
		if (cmo != null) {
			if (amount.compareTo(cmo) < 0) {
				optType = "qt_rec";
				amount = cmo.subtract(amount);
			} else {
				amount = amount.subtract(cmo);
			}
		}
		AcctTxRec txRec = new AcctTxRec();
		txRec.setTxId(SystemUtil.getUUID());
		txRec.setTxSn(txRec.getTxId());

		txRec.setTxDt(SysDateUtil.getSystemDate());
		txRec.setTxTs(SysDateUtil.getSystemDateTime());
		txRec.setTxAbs("����������������������");
		txRec.setTxType(bizType);
		txRec.setOptType(optType);
		txRec.setTxSts("S");
		String sourceCode = SpringContextUtil.getProperty("system.code");
		txRec.setSrcCode(sourceCode);

		txRec.setDataScLvl("B");
		txRec.setCurrCode("QUOTA");
		txRec.setTxCashFlag("N");
		txRec.setTxReqFiCls("1");
		txRec.setTxOperator(CommonDataUtil.getCurEntId());

		return txRec;
	}
}
